<template>
	<view>
		<cu-custom :isBack="true">
			<block slot="content">我的发布</block>
		</cu-custom>
		<view class="box" style="position: relative;padding-bottom: 18px;" :style="{ paddingTop: iStatusBarHeight + 'px'}">
			<view class="grid text-center col-1" style="padding-top: 50px;"></view>
			<view class="cu-list menu sm-border card-menu">
				<view class="cu-form-group">
					<view class="title">代币名称：</view>
					<input :adjust-position="false" maxlength="300" cursor-spacing="10" placeholder="请如实填写代币名称"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">状态：</view>
					<input :adjust-position="false" maxlength="300" cursor-spacing="10" placeholder="请如实填写代币状态"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">链类型：</view>
					<input :adjust-position="false" maxlength="300" cursor-spacing="10" placeholder="请如实填写代币链类型"></input>
				</view>
				<view class="cu-form-group">
					<view class="title">代币Logo：</view>
					<view class="grid col-4 grid-square flex-sub" style="margin: 10px;">
						<view class="bg-img" v-for="(item,index) in imgList" :key="index" @tap="ViewImage" :data-url="imgList[index]">
						 <image :src="imgList[index]" mode="aspectFill"></image>
							<view class="cu-tag bg-red" @tap.stop="DelImg" :data-index="index">
								<text class='cuIcon-close'></text>
							</view>
						</view>
						<view class="solids" @tap="ChooseImage" v-if="imgList.length<1">
							<text class='cuIcon-cameraadd'></text>
						</view>
					</view>
				</view>
				<view class="cu-form-group">
					<view class="title">详细介绍：</view>
					<textarea maxlength="-1" :disabled="modalName!=null" @input="textareaBInput" placeholder="请如实填写代币相关信息"></textarea>
				</view>
			</view>
			<view class="padding flex flex-direction" @tap='tj'>
				<button class="cu-btn bg-green margin-tb-sm lg">提交</button>
			</view>
		</view>	
	</view>
</template>

<script>
	export default {
		data() {
			return {
				index: -1,
				imgList: '',
				modalName: null,
				textareaAValue: '',
				textareaBValue: '',
				serverUrl: 'http://china.jbwchina.net.cn/api/v1/upprooftousu',
				formData: {
					userID:2
				},
				img:'',
				iStatusBarHeight:0
			};
		},
		onLoad() {
			this.iStatusBarHeight = uni.getSystemInfoSync().statusBarHeight;
		},
		methods: {
			ChooseImage() {
				var _self = this
				uni.chooseImage({
					count: 1, //默认9
					sizeType: ['original', 'compressed'], //可以指定是原图还是压缩图，默认二者都有
					sourceType: ['album'], //从相册选择
					success: (res) => {
						console.log(res);
						_self.imgList = res.tempFilePaths
						var uper = uni.uploadFile({
							// 需要上传的地址
							url:this.config.webUrl+'upprooftousu',
							formData: this.formData,
							// filePath  需要上传的文件
							filePath: res.tempFilePaths[0],
							fileType: 'image',
							name: 'tousu',
							success(res1) {
								let data = JSON.parse(res1.data);
								console.log(data.data.url); 
								_self.img = data.data.url
							}
						});
					}
				});
			},
			ViewImage(e) {
				uni.previewImage({
					urls: this.imgList,
					current: e.currentTarget.dataset.url
				});
			},
			DelImg(e) {
				uni.showModal({
					content: '确定要删除吗？',
					cancelText: '再看看',
					confirmText: '再见',
					success: res => {
						if (res.confirm) {
							this.imgList.splice(e.currentTarget.dataset.index, 1)
						}
					}
				})
			},
			textareaAInput(e) {
				this.textareaAValue = e.detail.value
			},
			textareaBInput(e) {
				this.textareaBValue = e.detail.value
			},
	async	tj(){
				if(this.textareaBValue == ''){
					uni.showToast({
						title:'信息必填',
						icon:'none'
					})
					return;
				}
				
				let url = `/tousu`;
				let [err,res] = await this.$http.post(url,{
					content:this.textareaBValue,
					image:this.img
				},{
					token:true,
					checkToken:true
				});
				if (!this.$http.errorCheck(err,res)) {
					return
				}
				uni.showToast({
					title:res.data.msg,
					icon:'none'
				})
				
				// setTimeout(function(){
				// 	uni.navigateBack({
				// 		delta:1
				// 	})
				// },1000)
			},
			
		}
	}
</script>

<style>
	.box{
		min-height: 100Vh;
		width: 100vw;
		background: #FFFFFF;
		background-image: url(../../static/xqbg.png);
		background-repeat: no-repeat;
		background-size:100% 100%;
		-moz-background-size:100% 100%;
	}
	
	.cu-list.menu-avatar>.cu-item:after {
		border-bottom: unset;
	}
	
	.cu-form-group .title {
		min-width: calc(4em + 15px);
	}
</style>

